<template>
  <div class="tabs-container">
    <!-- 标签页导航 -->
    <div class="tabs-header">
      <div
        v-for="(tab, index) in tabs"
        :key="index"
        :class="['tab-item', { active: activeTabIndex === index }, { disabled: disabled }]"
        @click="disabled ? null : switchTab(index)">
        {{ tab.name }}
      </div>
    </div>

    <!-- 标签页内容 -->
    <div class="tabs-content">
      <!-- 图表标题 - 所有图表标签页共用 -->
      <div v-if="activeTabIndex < 4" class="chart-title">
        阻抗值变化率: {{ eitChangeRate }}
      </div>
      
      <!-- 插槽内容 -->
      <slot></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: 'TabsContainer',
  
  props: {
    // 标签页配置
    tabs: {
      type: Array,
      required: true
    },
    // 当前激活的标签页索引
    activeTabIndex: {
      type: Number,
      default: 0
    },
    // 是否禁用标签页切换
    disabled: {
      type: Boolean,
      default: false
    },
    // EIT值变化率
    eitChangeRate: {
      type: String,
      default: '0%'
    },
    // 当前选择的脑区
    selectedBrain: {
      type: String,
      default: 'left'
    }
  },
  
  methods: {
    /**
     * 切换标签页
     * @param {Number} index - 标签页索引
     */
    switchTab(index) {
      if (this.activeTabIndex === index) return
      this.$emit('update:activeTabIndex', index)
      this.$emit('tab-changed', index)
    }
  }
}
</script>

<style scoped lang="scss">
.tabs-container {
  width: 100%;
  
  .tabs-header {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;

    .tab-item {
      padding: 8px 15px;
      cursor: pointer;
      font-size: 14px;
      color: #666;
      position: relative;
      transition: all 0.3s ease;
      border-radius: 20px;
      background-color: #f5f5f5;
      border: 2px solid #ccc;
      text-align: center;
      min-width: 100px;

      &:hover {
        color: #4a90e2;
        border-color: #4a90e2;
      }

      &.active {
        color: #4de6c2;
        font-weight: bold;
        border: 2px solid #4de6c2;
        box-shadow: 0 2px 8px rgba(77, 230, 194, 0.3);
      }

      &.disabled {
        color: #ccc;
        cursor: not-allowed;
        border-color: #ddd;
        background-color: #f0f0f0;
        opacity: 0.7;
        
        &:hover {
          color: #ccc;
          border-color: #ddd;
        }
      }
    }
  }

  .tabs-content {
    min-height: 200px;
    max-height: 450px;
    overflow-y: auto;
    
    .chart-title {
      text-align: right;
      font-size: 14px;
      color: #666;
      margin-bottom: 8px;
    }
  }
}
</style> 